package com.xiaotao.learn.algorithm.backtrack;

import java.util.LinkedList;
import java.util.List;

class Solution {
    String[] tb = new String[]{
            "abc",
            "def",
            "ghi",
            "jkl",
            "mno",
            "pqrs",
            "tuv",
            "wxyz"
    };
    LinkedList<String> res = new LinkedList<>();
    int len;
    char[] tmp;
    public List<String> letterCombinations(String digits) {
        len = digits.length();
        tmp = new char[len];
        if (len == 0) {
            return res;
        }
        find(0, digits);
        return res;
    }

    public void find(int index, String digits) {
        if(index == len) {
            res.add(String.valueOf(tmp));
        } else {
            String pattern = tb[digits.charAt(index) - 50];
            for (int i = 0; i < pattern.length(); i++) {
                tmp[index] = pattern.charAt(i);
                find(index + 1, digits);
            }
        }
    }
}
/**
 * https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/
 */
public class PhoneNumber {
    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.letterCombinations("3").forEach(System.out::println);
    }
}
